<?php 
## include required files
/*******************************/
require_once '../model/config.php';
/*******************************/
## Create Objects
/*******************************/
$configObj = new Model_Config();
/*******************************/
##logo dimension message
$smarty->assign('logo_dimension', LOGO_WIDTHHEIGHT);

##fetching the logo
$confiArr=$configObj->getConfigValueById(1);
$smarty->assign('confiArr', $confiArr);

if(isset($_POST['changelogo_btn'])) {
	$size =	getimagesize($_FILES['logo']['tmp_name']);
	## apply PHP validation for required filed
	if($_FILES['logo']['name']!= '' && ($size[0] >= LOGOWIDTH && $size[1] >= LOGOHEIGHT) ) {
			
			##unlink the prevoius logo
			$logo_image = '../uploads/logo/'.$confiArr['config_value']; 
			@unlink($logo_image);
			
			$path = '../uploads/logo/';
			$imageName    = $_FILES['logo']['name'];
			$arrImageName = explode(".",$imageName);
			$position     = count($arrImageName);
			$fileName     = date('Ymdhis').".".$arrImageName[$position-1];
			copy($_FILES["logo"]["tmp_name"],$path.$fileName);
			$logoArray=array();
			$logoArray['config_value']=$fileName;
			$configObj->editConfigVlaueById($logoArray,1);
			$_SESSION['msg'] = "<div class='success_msg'><span>You have successfully changed logo</span></div>";
			header('location:'.SITE_URL.'/admin/home.php?q=defaultsettings');
			exit;
		
	} else {// php validation else
		$_SESSION['msg'] = "<div class='error_msg'><span>".LOGO_WIDTHHEIGHT."</span></div>";
	}
	// main if closed
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Unset all the objects created which are on this page
unset($configObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'settings/uploadlogo.tpl');
unset($smarty);
?>